/*
 * \brief  Core-specific region manager session
 * \author Norman Feske
 * \date   2006-07-12
 */

/*
 * Copyright (C) 2006-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _CORE__INCLUDE__CORE_RM_SESSION_H_
#define _CORE__INCLUDE__CORE_RM_SESSION_H_

#include <base/server.h>

#include "dataspace_component.h"

namespace Genode {

	/**
	 * Region manager that uses the physical dataspace
	 * addresses directly as virtual addresses.
	 */
	class Core_rm_session : public Rm_session
	{
		private:

			Server_entrypoint *_ds_ep;

		public:

			Core_rm_session(Server_entrypoint *ds_ep): _ds_ep(ds_ep) { }

			void *attach(Dataspace_capability ds_cap, size_t size=0,
			             off_t offset=0, bool use_local_addr = false, addr_t local_addr = 0)
			{
				Dataspace_component *ds = static_cast<Dataspace_component *>(_ds_ep->obj_by_cap(ds_cap));
				if (!ds)
					throw Invalid_dataspace();

				return (void *)ds->phys_addr();
			}

			void detach(void *local_addr) { }

			Thread_capability add_client(Thread_capability thread) {
				return Thread_capability(); }

			void fault_handler(Signal_receiver_capability handler) { }

			State state() { return State(); }

			Dataspace_capability dataspace() { return Dataspace_capability(); }
	};
}

#endif /* _CORE__INCLUDE__CORE_RM_SESSION_H_ */
